package com.zb.sannuo.pharmacy.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.sannuo.common.domain.Drugstore;
import com.zb.sannuo.common.domain.UserLogin;
import com.zb.sannuo.common.domain.UserRole;
import com.zb.sannuo.common.domain.search.DrugstoreInfo;
import com.zb.sannuo.common.domain.vo.DrugstoreInfoVo;
import com.zb.sannuo.pharmacy.mapper.DrugstoreMapper;
import com.zb.sannuo.pharmacy.service.DrugstoreService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;

@Service
public class DrugstoreServiceImpl extends ServiceImpl<DrugstoreMapper, DrugstoreInfo> implements DrugstoreService {

    @Resource
    private DrugstoreMapper drugstoreMapper;

    @Override
    public Page selectMDListPage(int current, int number, DrugstoreInfoVo drugstoreInfoVo) {

        System.out.println(drugstoreInfoVo);
        Page page = new Page(current, number);
        return page.setRecords(drugstoreMapper.findDrugstoreMenDian(page,drugstoreInfoVo));

    }

    @Override
    public Page selectFDListPage(int current, int number, DrugstoreInfoVo drugstoreInfoVo) {

        System.out.println(drugstoreInfoVo);
        Page page = new Page(current, number);
        return page.setRecords(drugstoreMapper.findDrugstoreFenDian(page,drugstoreInfoVo));
    }

    @Transactional(timeout = 5)
    @Override
    public boolean addSubStore(Drugstore drugstore, UserLogin userLogin, UserRole userRole) {

        drugstore.setCustomerCode("1314");
        userLogin.setPassword("000000");
        userLogin.setCustomerCode("1314");
        userLogin.setStatus(1);
        int i = drugstoreMapper.addDrugstore(drugstore);
        int i1 = drugstoreMapper.addUserLogin(userLogin);
        int i2 = drugstoreMapper.addUserStore(userLogin.getUserId(), drugstore.getStoreId());
        int i3 = drugstoreMapper.addUserRole(userLogin.getUserId(), userRole.getRoleId());

        boolean bo = false;
        if (i+i1+i2+i3 == 4){
            bo = true;
        }
        return bo;

    }

}
